package com.cy.pj.sys.service.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Order(1)
@Aspect
@Component
public class SysTimeAspect
{
    @Pointcut("@annotation(com.cy.pj.common.annotation.RequiredTime)")
    public void doTime()
    {
    }

    @Before("doTime()")
    public void doBefore()
    {
        System.out.println("@Before");
    }

    @After("doTime()")
    public void doAfter()
    {
        System.out.println("@After");
    }

    @AfterReturning("doTime()")
    public void doAfterReturning()
    {
        System.out.println("@AfterReturning");
    }

    @AfterThrowing("doTime()")
    public void doAfterThrowing()
    {
        System.out.println("@AfterThrowing");
    }

    //最重要,优先级也是最高
    @Around("doTime()")
    public Object doAround(ProceedingJoinPoint joinPoint)
            throws Throwable
    {
        try
        {
            System.out.println("@Around.Before");
            Object result = joinPoint.proceed();
            System.out.println("@Around.AfterReturning");
            return result;
        }
        catch (Exception e)
        {
            System.out.println("@Around.AfterThrowing");
            e.printStackTrace();
            throw e;
        }
        finally
        {
            System.out.println("@Around.After");
        }
    }
    /*
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable
    {
        try{
            System.out.Println("@Around.Before");
            Object result = joinPoint.proceed();
            System.out.println("@Around.AfterReturning");
            return result;
        }catch (Exception e){
            System.out.Println("@Around.AfterThrowing);
            e.printStackTrace();
            throw e;
        }finally{
            System.out.println("@Around.After");
        }
    }
     */
}
